<template>
  <div class="homepage-hero-module">
    <div class="video-container">
      <div :style="fixStyle" class="filter">
        <div style="width: 400px; margin: 100px auto">
          <div style="font-size: 30px; text-align: center; padding: 30px 0;color: white">欢迎注册</div>
          <el-form ref="form" :model="form" size="normal" :rules="rules">
            <el-form-item prop="username">
              <el-input prefix-icon="el-icon-user-solid" v-model="form.username" placeholder="请输入账号"></el-input>
            </el-form-item>
            <el-form-item prop="password">
              <el-input prefix-icon="el-icon-lock" v-model="form.password" show-password placeholder="请输入密码"></el-input>
            </el-form-item>
            <el-form-item prop="confirm">
              <el-input prefix-icon="el-icon-lock" v-model="form.confirm" show-password placeholder="请确认密码"></el-input>
            </el-form-item>
            <el-form-item prop="nickName">
              <el-input prefix-icon="el-icon-user" v-model="form.nickName" placeholder="请输入昵称"></el-input>
            </el-form-item>
            <el-form-item prop="age">
              <el-input prefix-icon="el-icon-timer" v-model.number="form.age" placeholder="请输入年龄"></el-input>
            </el-form-item>
            <el-form-item  prop="sex">
              <el-radio v-model="form.sex" :label="'男'" style="color: white">男</el-radio>
              <el-radio v-model="form.sex" :label="'女'" style="color: white">女</el-radio>
            </el-form-item>
            <el-form-item prop="address">
              <el-select v-model="form.address" placeholder="请选择省份">
                <el-option
                    v-for="item in options"
                    :key="item.value"
                    :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button style="width: 100%" type="primary" @click="register">注册</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
      <video :style="fixStyle" autoplay loop muted class="fillWidth" v-on:canplay="canplay">
        <source src="../assets/sea.mp4" type="video/mp4"/>
        浏览器不支持 video 标签，建议升级浏览器。
      </video>
      <div style="width: 100%; height: 100vh; overflow: hidden;" :style="bg,fixStyle"> <!--  :style="bg" 加背景图片-->
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Register",
  data() {
    return {
      form: {},
      fixStyle: '',
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],
        confirm: [
          {required: true, message: '请确认密码', trigger: 'blur'},
        ],
        nickName: [
          {required: true, message: '请输入昵称', trigger: 'blur'},
        ],
        age: [
          {required: true, message: '请输入年龄', trigger: 'blur'},
        ],
        sex: [
          {required: true, message: '请输入性别', trigger: 'blur'},
        ],
        address: [
          {required: true, message: '请输入省份', trigger: 'blur'},
        ],
      },
      bg: {
        backgroundImage: "url(" + require("@/assets/bg.jpg") + ")",
        backgroundRepeat: "no-repeat",
        backgroundSize: "100% 100%"
      },
      options: [{
        value: '辽宁省',
      }, {
        value: '山西省',
      }, {
        value: '吉林省',
      }, {
        value: '河北省',
      }, {
        value: '黑龙江省',
      }, {
        value: '江苏省',
      }, {
        value: '浙江省',
      }, {
        value: '安徽省',
      }, {
        value: '江西省',
      }, {
        value: '福建省',
      }, {
        value: '山东省',
      }, {
        value: '河南省',
      }, {
        value: '湖北省',
      }, {
        value: '湖南省',
      }, {
        value: '广东省',
      }, {
        value: '海南省',
      }, {
        value: '四川省',
      }, {
        value: '贵州省',
      }, {
        value: '云南省',
      }, {
        value: '陕西省',
      }, {
        value: '甘肃省',
      }, {
        value: '青海省',
      }]
    }
  },
  methods: {
    canplay() {
      this.vedioCanPlay = true
    },
    register() {

      if (this.form.password !== this.form.confirm) {
        this.$message({
          type: "error",
          message: '2次密码输入不一致！'
        })
        return
      }

      this.$refs['form'].validate((valid) => {
        if (valid) {
          request.post("/user/register", this.form).then(res => {
            if (res.code === '0') {
              this.$message({
                type: "success",
                message: "注册成功"
              })
              this.$router.push("/login")  //登录成功之后进行页面的跳转，跳转到主页
            } else {
              this.$message({
                type: "error",
                message: res.msg
              })
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>

.homepage-hero-module,
.video-container {
  position: relative;
  height: 100vh;
  overflow: hidden;
}

.video-container .poster img {
  z-index: 0;
  position: absolute;
}

.video-container .filter {
  z-index: 1;
  position: absolute;
  background: rgba(0, 0, 0, 0.4);
  width: 100%;
  height: 100%;
}

.fillWidth {
  width: 100%;
}
</style>
